<template>
	<view>
		<view>
			<view>
				<view class="header"><image src="../../static/img/log.png"></image></view>
				<view class="content">
					<view style="color: #333333;">申请获取以下权限</view>
					<text>获得你的公开信息(昵称，头像、地区等)</text>
				</view>
				<button class="bottom" @tap="wxgzhlogin" :style="{background:newColor.color}">授权登录</button>
			</view>
		</view>
	</view>
</template>

<script>
import { getRecommend } from '../../static/utils/ahth.js';
export default {
	data() {
		return {
			codes: ''
		};
	},
	methods: {
		getUrlParam() {
			//用来截取微信回调链接中的code
			let name = 'code';
			var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
			let herf = window.location.href;
			let url = herf.split('#')[0];
			let search = url.split('?')[1];
			if (search) {
				var r = search.substr(0).match(reg);
				if (r !== null) {
					this.codes = unescape(r[2]);
				} else {
					return null;
				}
			} else {
				return null;
			}
		},
		wxgzhlogin() {
			console.log('点击了')
			if(this.codes !== ''){
				uni.request({
					url: 'https://zhiyuan.soft.haoyangsoft.com/api/index/mpLogin',
					data: {
						code: this.codes,
						recommend: getRecommend()
					},
					method: 'POST',
					success(res) {
						console.log('数组', res);
						if (res.data.code == 0) { //用户注册了
							setToken(res.data.data.token);
							// 直接跳转到个人中心
							this.$Router.pushTab({path:'/pages/tabBar/user/user'})
						} else if (res.data.code == 200) { //用户未注册
							setopenId(res.data.data);
							// 调用注册方法
							this.openid = res.data.data
							this.register()
						}
					}
				});
			}
		},
		register(){
			console.log('这是一个注册方法')  //注册完毕之后进入个人中心
		}
	},
	onLoad() {
		this.getUrlParam();
	}
};
</script>

<style lang="scss" scoped>
.header {
	margin: 90rpx 0 90rpx 50rpx;
	border-bottom: 1px solid #ccc;
	text-align: center;
	width: 650rpx;
	height: 300rpx;
	line-height: 450rpx;
	overflow: hidden;
}

.header image {
	width: 200rpx;
	height: 200rpx;
	border-radius: 50%;
	box-shadow: 5upx 2upx 12upx #cccccc;
}

.content {
	margin-left: 50rpx;
	margin-bottom: 90rpx;
}

.content text {
	display: block;
	color: #9d9d9d;
	margin-top: 40rpx;
	font-size: 24upx;
}

.bottom {
	border-radius: 80rpx;
	height: 80rpx;
	line-height: 80rpx;
	margin: 70rpx 50rpx;
	font-size: 35rpx;
	background-color: #F23A3A;
	color: #FFFFFF;
	width: 70vw;
	margin: 0 auto;
	border: none;
}
</style>
